//
//  STEUserModel.m
//  ste
//
//  Created by iRDC on 7/4/13.
//  Copyright (c) 2013 Lekima. All rights reserved.
//

#import "STEUserModel.h"
#import "RequestManager.h"
@implementation STEUserModel
@synthesize m_id;
@synthesize m_username;
@synthesize m_password;
@synthesize m_avatar_url;
- (NSURL *)avatarImageURL
{
    return [NSURL URLWithString:m_avatar_url];
}
+ (void)getUserWithBlock:(void (^)(NSArray *posts, NSError *error))block {
    [[RequestManager sharedClient] getPath:@"stream/0/posts/stream/global" parameters:nil success:^(AFHTTPRequestOperation *operation, id JSON) {
        
//        NSLog(@"%@",JSON);
        NSMutableArray *mutablePosts = [STEUserModel arrayOfModelsFromDictionaries:[JSON valueForKeyPath:@"data"]];
        
        if (block) {
            block([NSArray arrayWithArray:mutablePosts], nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (block) {
            block([NSArray array], error);
        }
    }];
}
+ (void)postUserLogginWithBlock:(STEUserModel*) user andBlock:(void (^)(NSArray *posts, NSError *error))block {
    
    NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                            user.m_id, @"userID",
                            @"test", @"password",
                            nil];
    [[RequestManager sharedClient] postPath:@"stream/0/posts/stream/global" parameters:params success:^(AFHTTPRequestOperation *operation, id JSON) {
//        NSLog(@"%@",JSON);
        NSMutableArray *mutablePosts = [STEUserModel arrayOfModelsFromDictionaries:[JSON valueForKeyPath:@"data"]];
        
        if (block) {
            block([NSArray arrayWithArray:mutablePosts], nil);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (block) {
            block([NSArray array], error);
        }
    }];
    
}
@end
